get_ac_init_version(${Clp_DIR}/configure.ac CLP)

option(CLP_BUILD_EXAMPLES "Enable the building of examples" OFF)

if (CLP_MAJOR_VERSION STREQUAL "devel")
  set(CLP_VERSION_MAJOR   "1"      CACHE STRING "The CLP major version number" FORCE)
  set(CLP_VERSION_MINOR   "17"     CACHE STRING "The CLP minor version number" FORCE)
  set(CLP_VERSION_RELEASE "6"      CACHE STRING "The CLP patch version number" FORCE)
  set(CLP_VERSION         "1.17.6" CACHE STRING "The CLP version" FORCE)
else ()
  set(CLP_VERSION_MAJOR   "${CLP_MAJOR_VERSION}"  CACHE STRING "The CLP major version number" FORCE)
  set(CLP_VERSION_MINOR   "${CLP_MINOR_VERSION}"  CACHE STRING "The CLP minor version number" FORCE)
  set(CLP_VERSION_RELEASE "${CLP_PATCH_VERSION}"  CACHE STRING "The CLP patch version number" FORCE)
  set(CLP_VERSION         "${CLP_VERSION_STRING}" CACHE STRING "The CLP version" FORCE)
endif ()

set(CLP_WC_REVISION "0")
if ((EXISTS "${Clp_DIR}/.svn") OR (EXISTS "${Clp_DIR}/../.svn"))
  find_package(Subversion)
  if (Subversion_FOUND)
    Subversion_WC_INFO(${Clp_DIR} CLP)
  endif ()
endif ()

if ((EXISTS "${Clp_DIR}/.git") OR (EXISTS "${Clp_DIR}/../.git"))
  find_package(Git)
  if (Git_FOUND)
    include(export_git)
    GIT_WC_INFO(${Clp_DIR} CLP)
    set(CLP_WC_REVISION "${CLP_WC_SVNEQUIV}") # alphanumeric rev not yet managed
  endif ()
endif ()

message(STATUS "Current CLP revision is ${CLP_WC_REVISION}")
set(CLP_SVN_REV "${CLP_WC_REVISION}" CACHE STRING "The CLP subversion revision" PARENT_SCOPE)

mark_as_advanced(CLP_VERSION_MAJOR
                 CLP_VERSION_MINOR
                 CLP_VERSION_RELEASE
                 CLP_VERSION
                 CLP_SVN_REV)

add_definitions(-DCLPLIB_BUILD)

if (CMAKE_COMPILER_IS_GNUCXX)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors -Wparentheses -Wreturn-type -Wcast-qual -Wall -Wpointer-arith -Wwrite-strings -Wconversion -Wno-unknown-pragmas -Wno-long-long")
endif ()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/config.h.in        ${CMAKE_BINARY_DIR}/Clp/include/config.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/config_clp.h.in    ${CMAKE_BINARY_DIR}/Clp/include/config_clp.h)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/config_osiclp.h.in ${CMAKE_BINARY_DIR}/Clp/include/config_osiclp.h)

#
# pkg-config file generation
#

set(prefix           "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix      "\${prefix}")
set(libdir           "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
set(includedir       "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
set(CLPLIB_PCLIBS     "")
set(CLPLIB_PCREQUIRES "coinutils")
set(PACKAGE_VERSION   "${CLP_VERSION}")

configure_file(${Clp_DIR}/clp.pc.in ${CMAKE_BINARY_DIR}/Clp/clp.pc @ONLY)

set(libdir         "${Clp_DIR}")
set(abs_source_dir "${CMAKE_BINARY_DIR}/bin")

install(FILES ${CMAKE_BINARY_DIR}/Clp/clp.pc
        DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkg-config/)

#
# Build
#

set(Clp_SRC_LIST ${Clp_DIR}/src/ClpCholeskyBase.cpp
                 ${Clp_DIR}/src/ClpCholeskyDense.cpp
                 ${Clp_DIR}/src/ClpConstraint.cpp
                 ${Clp_DIR}/src/ClpConstraintLinear.cpp
                 ${Clp_DIR}/src/ClpConstraintQuadratic.cpp
                 ${Clp_DIR}/src/Clp_C_Interface.cpp
                 ${Clp_DIR}/src/ClpDualRowDantzig.cpp
                 ${Clp_DIR}/src/ClpDualRowPivot.cpp
                 ${Clp_DIR}/src/ClpDualRowSteepest.cpp
                 ${Clp_DIR}/src/ClpDummyMatrix.cpp
                 ${Clp_DIR}/src/ClpDynamicExampleMatrix.cpp
                 ${Clp_DIR}/src/ClpDynamicMatrix.cpp
                 ${Clp_DIR}/src/ClpEventHandler.cpp
                 ${Clp_DIR}/src/ClpFactorization.cpp
                 ${Clp_DIR}/src/ClpGubDynamicMatrix.cpp
                 ${Clp_DIR}/src/ClpGubMatrix.cpp
                 ${Clp_DIR}/src/ClpHelperFunctions.cpp
                 ${Clp_DIR}/src/ClpInterior.cpp
                 ${Clp_DIR}/src/ClpLinearObjective.cpp
                 ${Clp_DIR}/src/ClpMatrixBase.cpp
                 ${Clp_DIR}/src/ClpMessage.cpp
                 ${Clp_DIR}/src/ClpModel.cpp
                 ${Clp_DIR}/src/ClpNetworkBasis.cpp
                 ${Clp_DIR}/src/ClpNetworkMatrix.cpp
                 ${Clp_DIR}/src/ClpNonLinearCost.cpp
                 ${Clp_DIR}/src/ClpNode.cpp
                 ${Clp_DIR}/src/ClpObjective.cpp
                 ${Clp_DIR}/src/ClpPackedMatrix.cpp
                 ${Clp_DIR}/src/ClpPlusMinusOneMatrix.cpp
                 ${Clp_DIR}/src/ClpPredictorCorrector.cpp
                 ${Clp_DIR}/src/ClpPdco.cpp
                 ${Clp_DIR}/src/ClpPdcoBase.cpp
                 ${Clp_DIR}/src/ClpLsqr.cpp
                 ${Clp_DIR}/src/ClpPresolve.cpp
                 ${Clp_DIR}/src/ClpPrimalColumnDantzig.cpp
                 ${Clp_DIR}/src/ClpPrimalColumnPivot.cpp
                 ${Clp_DIR}/src/ClpPrimalColumnSteepest.cpp
                 ${Clp_DIR}/src/ClpQuadraticObjective.cpp
                 ${Clp_DIR}/src/ClpSimplex.cpp
                 ${Clp_DIR}/src/ClpSimplexDual.cpp
                 ${Clp_DIR}/src/ClpSimplexNonlinear.cpp
                 ${Clp_DIR}/src/ClpSimplexOther.cpp
                 ${Clp_DIR}/src/ClpSimplexPrimal.cpp
                 ${Clp_DIR}/src/ClpSolve.cpp
                 ${Clp_DIR}/src/Idiot.cpp
                 ${Clp_DIR}/src/IdiSolve.cpp
                 ${Clp_DIR}/src/ClpPEPrimalColumnSteepest.cpp
                 ${Clp_DIR}/src/ClpPESimplex.cpp
                 ${Clp_DIR}/src/ClpPEDualRowSteepest.cpp
                 ${Clp_DIR}/src/ClpPEDualRowDantzig.cpp
                 ${Clp_DIR}/src/ClpPEPrimalColumnDantzig.cpp)

set(ClpSolver_SRC_LIST ${Clp_DIR}/src/ClpSolver.cpp
                       ${Clp_DIR}/src/CbcOrClpParam.cpp
                       ${Clp_DIR}/src/MyEventHandler.cpp
                       ${Clp_DIR}/src/MyMessageHandler.cpp
                       ${Clp_DIR}/src/unitTest.cpp)

if (COIN_HAS_ASL)
  set(ClpSolver_SRC_LIST ${ClpSolver_SRC_LIST}
                         ${Clp_DIR}/src/Clp_ampl.cpp)
endif ()

if (COIN_HAS_ABC)
  set(Clp_SRC_LIST ${Clp_SRC_LIST}
                   ${Clp_DIR}/src/AbcDualRowDantzig.cpp
                   ${Clp_DIR}/src/AbcDualRowPivot.cpp
                   ${Clp_DIR}/src/AbcDualRowSteepest.cpp
                   ${Clp_DIR}/src/AbcMatrix.cpp
                   ${Clp_DIR}/src/AbcNonLinearCost.cpp
                   ${Clp_DIR}/src/AbcPrimalColumnDantzig.cpp
                   ${Clp_DIR}/src/AbcPrimalColumnPivot.cpp
                   ${Clp_DIR}/src/AbcPrimalColumnSteepest.cpp
                   ${Clp_DIR}/src/AbcSimplex.cpp
                   ${Clp_DIR}/src/AbcSimplexDual.cpp
                   ${Clp_DIR}/src/AbcSimplexPrimal.cpp
                   ${Clp_DIR}/src/AbcSimplexParallel.cpp
                   ${Clp_DIR}/src/AbcSimplexFactorization.cpp
                   ${Clp_DIR}/src/AbcWarmStart.cpp
                   ${Clp_DIR}/src/CoinAbcBaseFactorization1.cpp
                   ${Clp_DIR}/src/CoinAbcBaseFactorization2.cpp
                   ${Clp_DIR}/src/CoinAbcBaseFactorization3.cpp
                   ${Clp_DIR}/src/CoinAbcBaseFactorization4.cpp
                   ${Clp_DIR}/src/CoinAbcBaseFactorization5.cpp
                   ${Clp_DIR}/src/CoinAbcDenseFactorization.cpp
                   ${Clp_DIR}/src/CoinAbcFactorization1.cpp
                   ${Clp_DIR}/src/CoinAbcFactorization2.cpp
                   ${Clp_DIR}/src/CoinAbcFactorization3.cpp
                   ${Clp_DIR}/src/CoinAbcFactorization4.cpp
                   ${Clp_DIR}/src/CoinAbcFactorization5.cpp
                   ${Clp_DIR}/src/CoinAbcHelperFunctions.cpp
                   ${Clp_DIR}/src/CoinAbcOrderedFactorization1.cpp
                   ${Clp_DIR}/src/CoinAbcOrderedFactorization2.cpp
                   ${Clp_DIR}/src/CoinAbcOrderedFactorization3.cpp
                   ${Clp_DIR}/src/CoinAbcOrderedFactorization4.cpp
                   ${Clp_DIR}/src/CoinAbcOrderedFactorization5.cpp
                   ${Clp_DIR}/src/CoinAbcSmallFactorization1.cpp
                   ${Clp_DIR}/src/CoinAbcSmallFactorization2.cpp
                   ${Clp_DIR}/src/CoinAbcSmallFactorization3.cpp
                   ${Clp_DIR}/src/CoinAbcSmallFactorization4.cpp
                   ${Clp_DIR}/src/CoinAbcSmallFactorization5.cpp)
endif ()
           
if (COIN_HAS_AMD OR COIN_HAS_CHOLMOD OR COIN_HAS_GLPK)
  set(Clp_SRC_LIST ${Clp_SRC_LIST}
                   ${Clp_DIR}/src/ClpCholeskyUfl.cpp)
endif ()
if (COIN_HAS_MUMPS)
  set(Clp_SRC_LIST ${Clp_SRC_LIST}
                   ${Clp_DIR}/src/ClpCholeskyMumps.cpp)
endif ()
if (COIN_HAS_WSMP)
  set(Clp_SRC_LIST ${Clp_SRC_LIST}
                   ${Clp_DIR}/src/ClpCholeskyWssmp.cpp
                   ${Clp_DIR}/src/ClpCholeskyWssmpKKT.cpp)
endif ()

set(Clp_MAIN_SRC_LIST ${Clp_DIR}/src/ClpMain.cpp)

set(Clp_SRC_LIST_Headers ${Clp_DIR}/src/Clp_C_Interface.h
                         ${Clp_DIR}/src/ClpCholeskyBase.hpp
                         ${Clp_DIR}/src/ClpCholeskyDense.hpp
                         ${Clp_DIR}/src/ClpConstraint.hpp
                         ${Clp_DIR}/src/ClpConstraintLinear.hpp
                         ${Clp_DIR}/src/ClpConstraintQuadratic.hpp
                         ${Clp_DIR}/src/ClpDualRowDantzig.hpp
                         ${Clp_DIR}/src/ClpDualRowPivot.hpp
                         ${Clp_DIR}/src/ClpDualRowSteepest.hpp
                         ${Clp_DIR}/src/ClpDummyMatrix.hpp
                         ${Clp_DIR}/src/ClpDynamicExampleMatrix.hpp
                         ${Clp_DIR}/src/ClpDynamicMatrix.hpp
                         ${Clp_DIR}/src/ClpEventHandler.hpp
                         ${Clp_DIR}/src/ClpFactorization.hpp
                         ${Clp_DIR}/src/ClpGubDynamicMatrix.hpp
                         ${Clp_DIR}/src/ClpGubMatrix.hpp
                         ${Clp_DIR}/src/ClpInterior.hpp
                         ${Clp_DIR}/src/ClpLinearObjective.hpp
                         ${Clp_DIR}/src/ClpMatrixBase.hpp
                         ${Clp_DIR}/src/ClpMessage.hpp
                         ${Clp_DIR}/src/ClpModel.hpp
                         ${Clp_DIR}/src/ClpNetworkMatrix.hpp
                         ${Clp_DIR}/src/ClpNonLinearCost.hpp
                         ${Clp_DIR}/src/ClpNode.hpp
                         ${Clp_DIR}/src/ClpObjective.hpp
                         ${Clp_DIR}/src/ClpPackedMatrix.hpp
                         ${Clp_DIR}/src/ClpPdcoBase.hpp
                         ${Clp_DIR}/src/ClpPlusMinusOneMatrix.hpp
                         ${Clp_DIR}/src/ClpParameters.hpp
                         ${Clp_DIR}/src/ClpPresolve.hpp
                         ${Clp_DIR}/src/ClpPrimalColumnDantzig.hpp
                         ${Clp_DIR}/src/ClpPrimalColumnPivot.hpp
                         ${Clp_DIR}/src/ClpPrimalColumnSteepest.hpp
                         ${Clp_DIR}/src/ClpQuadraticObjective.hpp
                         ${Clp_DIR}/src/ClpSimplex.hpp
                         ${Clp_DIR}/src/ClpSimplexNonlinear.hpp
                         ${Clp_DIR}/src/ClpSimplexOther.hpp
                         ${Clp_DIR}/src/ClpSimplexDual.hpp
                         ${Clp_DIR}/src/ClpSimplexPrimal.hpp
                         ${Clp_DIR}/src/ClpSolve.hpp
                         ${Clp_DIR}/src/CbcOrClpParam.hpp
                         ${Clp_DIR}/src/Idiot.hpp
                         ${Clp_DIR}/src/ClpPEPrimalColumnDantzig.hpp
                         ${Clp_DIR}/src/ClpPEPrimalColumnSteepest.hpp
                         ${Clp_DIR}/src/ClpPESimplex.hpp
                         ${Clp_DIR}/src/ClpPEDualRowSteepest.hpp
                         ${Clp_DIR}/src/ClpPEDualRowDantzig.hpp)

if (COIN_HAS_ABC)
  set(Clp_SRC_LIST_Headers ${Clp_SRC_LIST_Headers}
                           ${Clp_DIR}/src/AbcSimplex.hpp
                           ${Clp_DIR}/src/CoinAbcCommon.hpp
                           ${Clp_DIR}/src/AbcCommon.hpp)
endif ()

# if AMD, CHOLMOD, or GLPK is available, then install ClpCholeskyUfl.hpp (for advanced users)
if (COIN_HAS_AMD OR COIN_HAS_CHOLMOD OR COIN_HAS_GLPK)
  set(Clp_SRC_LIST_Headers ${Clp_SRC_LIST_Headers}
                           ${Clp_DIR}/src/ClpCholeskyUfl.hpp)
endif ()
if (COIN_HAS_MUMPS)
  set(Clp_SRC_LIST_Headers ${Clp_SRC_LIST_Headers}
                           ${Clp_DIR}/src/ClpCholeskyMumps.hpp)
endif ()

if (COIN_HAS_WSMP)
  set(Clp_SRC_LIST_Headers ${Clp_SRC_LIST_Headers}
                           ${Clp_DIR}/src/ClpCholeskyWssmp.hpp
                           ${Clp_DIR}/src/ClpCholeskyWssmpKKT.hpp)
endif ()

if (CMAKE_COMPILER_IS_GNUCXX AND ((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4) OR (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.4)))
  set_source_files_properties(${Clp_DIR}/src/CbcOrClpParam.cpp PROPERTIES COMPILE_FLAGS -fno-var-tracking-assignments)
endif ()

add_definitions(-DCOIN_HAS_CLP)

if (COIN_HAS_AMD AND (NOT COIN_HAS_AMD_INCLUDE_PATH STREQUAL "None"))
  include_directories(${COIN_HAS_AMD_INCLUDE_PATH})
endif ()
if (COIN_HAS_CHOLMOD AND (NOT COIN_HAS_CHOLMOD_INCLUDE_PATH STREQUAL "None"))
  include_directories(${COIN_HAS_CHOLMOD_INCLUDE_PATH})
endif ()
if (COIN_HAS_GLPK AND (NOT COIN_HAS_GLPK_INCLUDE_PATH STREQUAL "None"))
  include_directories(${COIN_HAS_GLPK_INCLUDE_PATH})
endif ()
if (COIN_HAS_MUMPS AND (NOT COIN_HAS_MUMPS_INCLUDE_PATH STREQUAL "None"))
  include_directories(${COIN_HAS_MUMPS_INCLUDE_PATH})
endif ()
if (COIN_HAS_WSMP AND (NOT COIN_HAS_WSMP_INCLUDE_PATH STREQUAL "None"))
  include_directories(${COIN_HAS_WSMP_INCLUDE_PATH})
endif ()

include_directories(${CMAKE_SOURCE_DIR}/src)
include_directories(${BuildTools_DIR}/headers)
include_directories(SYSTEM ${CoinUtils_DIR}/src)
include_directories(${Clp_DIR}/src)
include_directories(${Clp_DIR}/src/OsiClp)
if (COIN_ENABLE_DOWNLOAD_ASL OR COIN_USE_ASL)
  include_directories(${CMAKE_BINARY_DIR}/Dependencies/${CMAKE_CFG_INTDIR}/include/ampl)
endif ()

macro(set_include_directories TARGET)
  target_include_directories(${TARGET} BEFORE PRIVATE ${CMAKE_BINARY_DIR}/CoinUtils/include)
  target_include_directories(${TARGET} BEFORE PRIVATE ${CMAKE_BINARY_DIR}/Osi/include)
  target_include_directories(${TARGET} BEFORE PRIVATE ${CMAKE_BINARY_DIR}/Clp/include)
endmacro ()

if (WIN32)
  add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE)
endif ()

remove_definitions(-DCBC_THREAD)

if (ENABLE_SHARED_LIBRARIES)
  add_library(libClp SHARED ${Clp_SRC_LIST})
else ()
  add_library(libClp STATIC ${Clp_SRC_LIST})
endif ()
if (COIN_COMPILE_LTO)
  set_target_properties(libClp PROPERTIES INTERPROCEDURAL_OPTIMIZATION true)
endif ()
if (NOT WIN32 OR MINGW)
  set_target_properties(libClp PROPERTIES PREFIX "")
endif ()

if (COIN_HAS_AMD AND (NOT COIN_HAS_AMD_LIBRARY_PATH STREQUAL "None"))
  link_directories(${COIN_HAS_AMD_LIBRARY_PATH})
endif ()
if (COIN_HAS_CHOLMOD AND (NOT COIN_HAS_CHOLMOD_LIBRARY_PATH STREQUAL "None"))
  link_directories(${COIN_HAS_CHOLMOD_LIBRARY_PATH})
endif ()
if (COIN_HAS_GLPK AND (NOT COIN_HAS_GLPK_LIBRARY_PATH STREQUAL "None"))
  link_directories(${COIN_HAS_GLPK_LIBRARY_PATH})
endif ()
if (COIN_HAS_MUMPS AND (NOT COIN_HAS_MUMPS_LIBRARY_PATH STREQUAL "None"))
  link_directories(${COIN_HAS_MUMPS_LIBRARY_PATH})
endif ()
if (COIN_HAS_WSMP AND (NOT COIN_HAS_WSMP_LIBRARY_PATH STREQUAL "None"))
  link_directories(${COIN_HAS_WSMP_LIBRARY_PATH})
endif ()
set_include_directories(libClp)

if (ENABLE_SHARED_LIBRARIES)
  add_library(libClpSolver SHARED ${ClpSolver_SRC_LIST})
else ()
  add_library(libClpSolver STATIC ${ClpSolver_SRC_LIST})
endif ()
if (COIN_COMPILE_LTO)
  set_target_properties(libClpSolver PROPERTIES INTERPROCEDURAL_OPTIMIZATION true)
endif ()
if (NOT WIN32)
  set_target_properties(libClpSolver PROPERTIES PREFIX "")
endif ()
set_include_directories(libClpSolver)

if (CLP_BUILD_EXAMPLES)
  set(TEST_LIB_PATH "${CMAKE_BINARY_DIR}/Dependencies/${CMAKE_CFG_INTDIR}/lib")
  set(TEST_BIN_PATH "${CMAKE_BINARY_DIR}/Dependencies/${CMAKE_CFG_INTDIR}/bin")
  
  #
  # Build Examples
  #
  macro(add_example Name)
    add_executable(${Name} ${ARGN})
    if (COIN_COMPILE_LTO)
      set_target_properties(${Name} PROPERTIES INTERPROCEDURAL_OPTIMIZATION true)
    endif ()
    if (COINUTILS_USE_THREADS OR COIN_USE_PTHREAD_WIN32 OR COIN_ENABLE_DOWNLOAD_PTHREAD_WIN32 OR CBC_USE_THREADS)
      if (MINGW)
        target_link_libraries(${Name} winpthread)
      elseif (NOT WIN32)
        target_link_libraries(${Name} pthread)
      else ()
        target_link_libraries(${Name} pthreadVC2)
      endif ()
    endif ()
    target_link_libraries(${Name} libClp libCoinUtils)
    set_include_directories(${Name})
    if (COIN_HAS_AMD)
      target_link_libraries(${Name} amd)
    endif ()
    if (COIN_HAS_CHOLMOD)
      target_link_libraries(${Name} cholmod suitesparseconfig amd ccolamd colamd camd)
    endif ()
    if (MKL_FOUND)
      target_link_libraries(${Name} ${COIN_MKL_LIBS})
    else ()
      if (COIN_HAS_LAPACK OR COIN_USE_SYSTEM_LAPACK)
        target_link_libraries(${Name} lapack)
      endif ()
      if (COIN_HAS_BLAS OR COIN_USE_BLAS)
        target_link_libraries(${Name} blas)
      endif ()
      if (COIN_ENABLE_DOWNLOAD_CLAPACK)
        target_link_libraries(${Name} f2c)
      endif ()
      if ((COIN_HAS_BLAS OR COIN_HAS_LAPACK) AND (UNIX OR MINGW) AND COIN_USE_SYSTEM_LAPACK AND NOT (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel"))
        target_link_libraries(${Name} gfortran)
      endif ()
    endif ()
    if (COINUTILS_HAS_ZLIB OR COIN_USE_ZLIB)
      target_link_libraries(${Name} ${ZLIB_NAME})
    endif ()
    if (COINUTILS_HAS_BZLIB OR COIN_USE_ZLIB)
      target_link_libraries(${Name} ${BZLIB_NAME})
    endif ()
    if (COIN_HAS_GLPK OR COIN_USE_GLPK)
      target_link_libraries(${Name} glpk)
    endif ()
    if (USE_OPENMP AND UNIX)
      target_link_libraries(${Name} gomp)
    endif ()
    if (COIN_HAS_ABC AND (COIN_ABC_LEVEL GREATER 2))
      target_link_libraries(${Name} cilkrts)
    endif ()  
    if (COIN_ENABLE_DOWNLOAD_ASL OR COIN_USE_ASL)
      target_link_libraries(${Name} amplsolver dl)
    endif ()  
    if (READLINE_FOUND)
      target_link_libraries(${Name} ${READLINE_LIBRARIES})
    endif ()  
    if (COIN_HAS_MUMPS)
      if (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
        target_link_libraries(${Name} dmumps mumps_common seq blas lapack ifort pthread)
      else ()
        target_link_libraries(${Name} dmumps mumps_common seq blas lapack gfortran pthread)
      endif ()
    endif ()  
    if (COIN_ENABLE_DOWNLOAD_METIS OR COIN_USE_METIS)
      target_link_libraries(${Name} metis m)
    endif ()  
  endmacro ()

  # This test hangs if COIN_BIG_INDEX==2
  add_example(addBits ${Clp_DIR}/examples/addBits.cpp)
  
  add_test(NAME clp_example_addBits
           COMMAND $<TARGET_FILE:addBits> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_addBits PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_addBits PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set_tests_properties(clp_example_addBits PROPERTIES PASS_REGULAR_EXPRESSION "Clp0000I Optimal - objective value -49.857")
  set_tests_properties(clp_example_addBits PROPERTIES LABELS "DISTRIB;FAILS;CLP;EXAMPLE")
    
  add_example(addColumns ${Clp_DIR}/examples/addColumns.cpp)
  
  add_test(NAME clp_example_addColumns
           COMMAND $<TARGET_FILE:addColumns> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_addColumns PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_addColumns PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set_tests_properties(clp_example_addColumns PROPERTIES PASS_REGULAR_EXPRESSION "Clp0032I Optimal objective -464.75.* - 5 iterations")
  set_tests_properties(clp_example_addColumns PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
    
  add_example(addRows ${Clp_DIR}/examples/addRows.cpp)
  
  add_test(NAME clp_example_addRows
           COMMAND $<TARGET_FILE:addRows> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_addRows PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_addRows PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set_tests_properties(clp_example_addRows PROPERTIES PASS_REGULAR_EXPRESSION "Clp0000I Optimal - objective value 1")
  set_tests_properties(clp_example_addRows PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
    
  add_example(decomp2 ${Clp_DIR}/examples/decomp2.cpp)

  add_test(NAME clp_example_decomp2
           COMMAND $<TARGET_FILE:decomp2> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_decomp2 PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_decomp2 PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set_tests_properties(clp_example_decomp2 PROPERTIES PASS_REGULAR_EXPRESSION "Clp0000I Optimal - objective value -464.75")
  set_tests_properties(clp_example_decomp2 PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
    
  add_example(decomp3 ${Clp_DIR}/examples/decomp3.cpp)
  
  add_test(NAME clp_example_decomp3
           COMMAND $<TARGET_FILE:decomp3> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_decomp3 PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_decomp3 PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set_tests_properties(clp_example_decomp3 PROPERTIES PASS_REGULAR_EXPRESSION "Clp0000I Optimal - objective value -464.75")
  set_tests_properties(clp_example_decomp3 PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
    
  add_example(decompose ${Clp_DIR}/examples/decompose.cpp)
  
  add_test(NAME clp_example_decompose
           COMMAND $<TARGET_FILE:decompose> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_decompose PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_decompose PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set_tests_properties(clp_example_decompose PROPERTIES PASS_REGULAR_EXPRESSION "Clp0000I Optimal - objective value -464.75")
  set_tests_properties(clp_example_decompose PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
    
  add_example(default ${Clp_DIR}/examples/defaults.cpp)
  
  add_test(NAME clp_example_default
           COMMAND $<TARGET_FILE:default> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_default PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_default PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set(TEST_REGEX )
  add_regex(TEST_REGEX "Column 0 \\\\( 23, 0.301\\\\) \\\\( 0, -1\\\\) \\\\( 1, -1.06\\\\) \\\\( 2, 1\\\\)")
  add_regex(TEST_REGEX "Column 1 \\\\( 3, -1\\\\) \\\\( 0, 1\\\\)")
  add_regex(TEST_REGEX "Column 2 \\\\( 21, -1\\\\) \\\\( 0, 1\\\\)")
  add_regex(TEST_REGEX "Column 3 \\\\( 25, 1\\\\) \\\\( 1, 1\\\\)")
  add_regex(TEST_REGEX "Column 4 \\\\( 24, 0.301\\\\) \\\\( 4, -1\\\\) \\\\( 5, -1.06\\\\) \\\\( 6, 1\\\\)")
  add_regex(TEST_REGEX "Column 5 \\\\( 24, 0.313\\\\) \\\\( 4, -1\\\\) \\\\( 5, -1.06\\\\) \\\\( 7, 1\\\\)")
  add_regex(TEST_REGEX "Column 6 \\\\( 24, 0.313\\\\) \\\\( 4, -1\\\\) \\\\( 5, -0.96\\\\) \\\\( 8, 1\\\\)")
  add_regex(TEST_REGEX "Column 7 \\\\( 24, 0.326\\\\) \\\\( 4, -1\\\\) \\\\( 5, -0.86\\\\) \\\\( 9, 1\\\\)")
  add_regex(TEST_REGEX "Column 8 \\\\( 20, 2.364\\\\) \\\\( 6, -1\\\\)")
  add_regex(TEST_REGEX "Column 9 \\\\( 20, 2.386\\\\) \\\\( 7, -1\\\\)")
  add_regex(TEST_REGEX "Column 10 \\\\( 20, 2.408\\\\) \\\\( 8, -1\\\\)")
  add_regex(TEST_REGEX "Column 11 \\\\( 20, 2.429\\\\) \\\\( 9, -1\\\\)")
  add_regex(TEST_REGEX "Column 12 \\\\( 3, 1.4\\\\) \\\\( 4, 1\\\\)")
  add_regex(TEST_REGEX "Column 13 \\\\( 22, -1\\\\) \\\\( 4, 1\\\\)")
  add_regex(TEST_REGEX "Column 14 \\\\( 26, 1\\\\) \\\\( 5, 1\\\\)")
  add_regex(TEST_REGEX "Column 15 \\\\( 21, 0.109\\\\) \\\\( 10, -1\\\\) \\\\( 11, -0.43\\\\) \\\\( 12, 1\\\\)")
  add_regex(TEST_REGEX "Column 16 \\\\( 13, -1\\\\) \\\\( 10, 1\\\\)")
  add_regex(TEST_REGEX "Column 17 \\\\( 23, -1\\\\) \\\\( 10, 1\\\\)")
  add_regex(TEST_REGEX "Column 18 \\\\( 20, -1\\\\) \\\\( 10, 1\\\\)")
  add_regex(TEST_REGEX "Column 19 \\\\( 25, 1\\\\) \\\\( 11, 1\\\\)")
  add_regex(TEST_REGEX "Column 20 \\\\( 22, 0.109\\\\) \\\\( 14, -0.43\\\\) \\\\( 15, 1\\\\) \\\\( 16, 1\\\\)")
  add_regex(TEST_REGEX "Column 21 \\\\( 22, 0.108\\\\) \\\\( 14, -0.43\\\\) \\\\( 15, 1\\\\) \\\\( 17, 1\\\\)")
  add_regex(TEST_REGEX "Column 22 \\\\( 22, 0.108\\\\) \\\\( 14, -0.39\\\\) \\\\( 15, 1\\\\) \\\\( 18, 1\\\\)")
  add_regex(TEST_REGEX "Column 23 \\\\( 22, 0.107\\\\) \\\\( 14, -0.37\\\\) \\\\( 15, 1\\\\) \\\\( 19, 1\\\\)")
  add_regex(TEST_REGEX "Column 24 \\\\( 20, 2.191\\\\) \\\\( 16, -1\\\\)")
  add_regex(TEST_REGEX "Column 25 \\\\( 20, 2.219\\\\) \\\\( 17, -1\\\\)")
  add_regex(TEST_REGEX "Column 26 \\\\( 20, 2.249\\\\) \\\\( 18, -1\\\\)")
  add_regex(TEST_REGEX "Column 27 \\\\( 20, 2.279\\\\) \\\\( 19, -1\\\\)")
  add_regex(TEST_REGEX "Column 28 \\\\( 13, 1.4\\\\) \\\\( 15, -1\\\\)")
  add_regex(TEST_REGEX "Column 29 \\\\( 24, -1\\\\) \\\\( 15, 1\\\\)")
  add_regex(TEST_REGEX "Column 30 \\\\( 26, 1\\\\) \\\\( 14, 1\\\\)")
  add_regex(TEST_REGEX "Column 31 \\\\( 15, 1\\\\)")
  
  set_tests_properties(clp_example_default PROPERTIES PASS_REGULAR_EXPRESSION "${TEST_REGEX}")
  set_tests_properties(clp_example_default PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
  
  add_example(driver2 ${Clp_DIR}/examples/driver2.cpp)
  
  add_test(NAME clp_example_driver2
           COMMAND $<TARGET_FILE:driver2> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_driver2 PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_driver2 PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set_tests_properties(clp_example_driver2 PROPERTIES PASS_REGULAR_EXPRESSION "Clp0000I Optimal - objective value -464.75")
  set_tests_properties(clp_example_driver2 PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
    
  add_example(driver ${Clp_DIR}/examples/driver.cpp)
  
  add_test(NAME clp_example_driver
           COMMAND $<TARGET_FILE:driver> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_driver PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_driver PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set(TEST_REGEX )
  add_regex(TEST_REGEX "Clp0032I Optimal objective -464.75.* - 5 iterations time .*, Presolve 0.00")
  add_regex(TEST_REGEX "Model AFIRO has 27 rows and 32 columns")
  set_tests_properties(clp_example_driver PROPERTIES PASS_REGULAR_EXPRESSION "${TEST_REGEX}")
  set_tests_properties(clp_example_driver PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
    
  add_example(dualCuts ${Clp_DIR}/examples/dualCuts.cpp)
  
  add_test(NAME clp_example_dualCuts
           COMMAND $<TARGET_FILE:dualCuts> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_dualCuts PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_dualCuts PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()

  set_tests_properties(clp_example_dualCuts PROPERTIES PASS_REGULAR_EXPRESSION "Clp0000I Optimal - objective value -464.75")
  set_tests_properties(clp_example_dualCuts PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
    
  # Needs ekk_api_c.h ...
  #add_example(ekk ${Clp_DIR}/examples/ekk.cpp)
  
  #add_example(ekk_interface ${Clp_DIR}/examples/ekk_interface.cpp)
  
  add_example(hello ${Clp_DIR}/examples/hello.cpp)
  
  add_test(NAME clp_example_hello
           COMMAND $<TARGET_FILE:hello> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_hello PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_hello PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set(TEST_REGEX )
  add_regex(TEST_REGEX "This prints x wherever a non-zero element exists in the matrix.")
  add_regex(TEST_REGEX "xxx                             ")
  add_regex(TEST_REGEX "x  x                            ")
  add_regex(TEST_REGEX "x                               ")
  add_regex(TEST_REGEX " x          x                   ")
  add_regex(TEST_REGEX "    xxxx    xx                  ")
  add_regex(TEST_REGEX "    xxxx      x                 ")
  add_regex(TEST_REGEX "    x   x                       ")
  add_regex(TEST_REGEX "     x   x                      ")
  add_regex(TEST_REGEX "      x   x                     ")
  add_regex(TEST_REGEX "       x   x                    ")
  add_regex(TEST_REGEX "               xxxx             ")
  add_regex(TEST_REGEX "               x   x            ")
  add_regex(TEST_REGEX "               x                ")
  add_regex(TEST_REGEX "                x           x   ")
  add_regex(TEST_REGEX "                    xxxx      x ")
  add_regex(TEST_REGEX "                    xxxx    xx x")
  add_regex(TEST_REGEX "                    x   x       ")
  add_regex(TEST_REGEX "                     x   x      ")
  add_regex(TEST_REGEX "                      x   x     ")
  add_regex(TEST_REGEX "                       x   x    ")
  add_regex(TEST_REGEX "        xxxx      x     xxxx    ")
  add_regex(TEST_REGEX "  x            x                ")
  add_regex(TEST_REGEX "             x      xxxx        ")
  add_regex(TEST_REGEX "x                x              ")
  add_regex(TEST_REGEX "    xxxx                     x  ")
  add_regex(TEST_REGEX "   x               x            ")
  add_regex(TEST_REGEX "              x               x ")
  
  set_tests_properties(clp_example_hello PROPERTIES PASS_REGULAR_EXPRESSION "${TEST_REGEX}")
  set_tests_properties(clp_example_hello PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
    
  add_example(makeDual ${Clp_DIR}/examples/makeDual.cpp)
  
  add_test(NAME clp_example_makeDual
           COMMAND $<TARGET_FILE:makeDual> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_makeDual PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_makeDual PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set_tests_properties(clp_example_makeDual PROPERTIES PASS_REGULAR_EXPRESSION "Coin0002I Problem AFIRO has 27 rows, 32 columns and 83 elements")
  set_tests_properties(clp_example_makeDual PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
    
  # Must compile minimum.cpp with -DSAMPLEDIR=${Data_DIR}
  add_example(minimum ${Clp_DIR}/examples/minimum.cpp)
  
  add_test(NAME clp_example_minimum
           COMMAND $<TARGET_FILE:minimum> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_minimum PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_minimum PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set_tests_properties(clp_example_minimum PROPERTIES PASS_REGULAR_EXPRESSION "Clp0000I Optimal - objective value -464.75")
  set_tests_properties(clp_example_minimum PROPERTIES LABELS "DISTRIB;FAIL;CLP;EXAMPLE")
  
  add_example(modify ${Clp_DIR}/examples/modify.cpp)
  
  add_test(NAME clp_example_modify
           COMMAND $<TARGET_FILE:modify> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_modify PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_modify PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set(TEST_REGEX )
  add_regex(TEST_REGEX "Column 5 has value 4")
  add_regex(TEST_REGEX "Column 6 has value 0.0475")
  set_tests_properties(clp_example_modify PROPERTIES PASS_REGULAR_EXPRESSION "${TEST_REGEX}")
  set_tests_properties(clp_example_modify PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
    
  add_example(network ${Clp_DIR}/examples/network.cpp)
  
  add_test(NAME clp_example_network
           COMMAND $<TARGET_FILE:network> ${Data_DIR}/input.130)
  set_tests_properties(clp_example_network PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_network PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set_tests_properties(clp_example_network PROPERTIES PASS_REGULAR_EXPRESSION "Clp0000I Optimal - objective value 38939608")
  set_tests_properties(clp_example_network PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")

  
  # This test hangs because it requires the following files:./g.tiny ./gparm.tiny in the exe directory
  execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Clp/examples/g.tiny     ${CMAKE_BINARY_DIR}/bin/
                  COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Clp/examples/gparm.tiny ${CMAKE_BINARY_DIR}/bin/)

  add_example(pdco ${Clp_DIR}/examples/pdco.cpp)
                   #${Clp_DIR}/examples/myPdco.cpp)
  
  add_test(NAME clp_example_pdco
           COMMAND $<TARGET_FILE:pdco> ${Data_DIR}/afiro.mps
           WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  set_tests_properties(clp_example_pdco PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_pdco PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set(TEST_REGEX )
  add_regex(TEST_REGEX "")
  add_regex(TEST_REGEX "Distribution of Solution Values")
  add_regex(TEST_REGEX " 0.1  to  1.00001 1")
  add_regex(TEST_REGEX " 0.01  to  0.1 14")
  add_regex(TEST_REGEX " 0.001  to  0.01 0")
  add_regex(TEST_REGEX " 0.0001  to  0.001 10")
  add_regex(TEST_REGEX " 1e-05  to  0.0001 3")
  add_regex(TEST_REGEX " 1e-06  to  1e-05 0")
  add_regex(TEST_REGEX " 1e-07  to  1e-06 0")
  add_regex(TEST_REGEX "   Less than   1e-06 0")
  
  set_tests_properties(clp_example_pdco PROPERTIES PASS_REGULAR_EXPRESSION "${TEST_REGEX}")
  set_tests_properties(clp_example_pdco PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")  
  
  add_example(piece ${Clp_DIR}/examples/piece.cpp)
  
  add_test(NAME clp_example_piece
           COMMAND $<TARGET_FILE:piece> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_piece PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_piece PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set(TEST_REGEX )
  add_regex(TEST_REGEX "Clp0000I Optimal - objective value -464.75")
  add_regex(TEST_REGEX "80 25.5 54.5 84.8 58.156 0 0 0 0 0 0 0 18.2143 39.9417 61.6454 500 475.92 24.08 0 215 366.438 0 0 0 0 0 0 0 339.943 17.505 157.568 0 ")
  
  set_tests_properties(clp_example_piece PROPERTIES PASS_REGULAR_EXPRESSION "${TEST_REGEX}")
  set_tests_properties(clp_example_piece PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
  
  add_example(rowColumn ${Clp_DIR}/examples/rowColumn.cpp)
  
  add_test(NAME clp_example_rowColumn
           COMMAND $<TARGET_FILE:rowColumn> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_rowColumn PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_rowColumn PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set(TEST_REGEX )
  add_regex(TEST_REGEX "Clp0000I Optimal - objective value 76000")
  add_regex(TEST_REGEX "Column 0 has value 8")
  add_regex(TEST_REGEX "Column 4 has value 6.8")
  
  set_tests_properties(clp_example_rowColumn PROPERTIES PASS_REGULAR_EXPRESSION "${TEST_REGEX}")
  set_tests_properties(clp_example_rowColumn PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")  
  
  add_example(sprint2 ${Clp_DIR}/examples/sprint2.cpp)
  
  add_test(NAME clp_example_sprint2
           COMMAND $<TARGET_FILE:sprint2> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_sprint2 PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_sprint2 PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set_tests_properties(clp_example_sprint2 PROPERTIES PASS_REGULAR_EXPRESSION "Clp0000I Optimal - objective value -464.75")
  set_tests_properties(clp_example_sprint2 PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
  
  add_example(sprint ${Clp_DIR}/examples/sprint.cpp)
  
  add_test(NAME clp_example_sprint
           COMMAND $<TARGET_FILE:sprint> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_sprint PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_sprint PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set_tests_properties(clp_example_sprint PROPERTIES PASS_REGULAR_EXPRESSION "Clp0000I Optimal - objective value -464.75")
  set_tests_properties(clp_example_sprint PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
  
  add_example(testBarrier ${Clp_DIR}/examples/testBarrier.cpp)
  
  add_test(NAME clp_example_testBarrier
           COMMAND $<TARGET_FILE:testBarrier> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_testBarrier PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_testBarrier PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set_tests_properties(clp_example_testBarrier PROPERTIES PASS_REGULAR_EXPRESSION "Clp0000I Optimal - objective value -464.75")
  set_tests_properties(clp_example_testBarrier PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
    
  add_example(testBasis ${Clp_DIR}/examples/testBasis.cpp)
  
  add_test(NAME clp_example_testBasis
           COMMAND $<TARGET_FILE:testBasis> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_testBasis PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_testBasis PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set_tests_properties(clp_example_testBasis PROPERTIES PASS_REGULAR_EXPRESSION "Clp0000I Optimal - objective value -464.75")
  set_tests_properties(clp_example_testBasis PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")

  #add_example(testGub2 ${Clp_DIR}/examples/testGub2.cpp)
  #
  #add_test(NAME clp_example_testGub2
  #         COMMAND $<TARGET_FILE:testGub2> ${Data_DIR}/afiro.mps)
  #set_tests_properties(clp_example_testGub2 PROPERTIES TIMEOUT 30)
  #if (WIN32)
  #  set_tests_properties(clp_example_testGub2 PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  #endif ()
  # 
  #set_tests_properties(clp_example_testGub2 PROPERTIES PASS_REGULAR_EXPRESSION "Clp0000I Optimal - objective value -464.75")
  #set_tests_properties(clp_example_testGub2 PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
  
  add_example(testGub ${Clp_DIR}/examples/testGub.cpp)
   
  add_test(NAME clp_example_testGub
           COMMAND $<TARGET_FILE:testGub> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_testGub PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_testGub PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set_tests_properties(clp_example_testGub PROPERTIES PASS_REGULAR_EXPRESSION "Clp0000I Optimal - objective value -464.75")
  set_tests_properties(clp_example_testGub PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
    
  add_example(testQP ${Clp_DIR}/examples/testQP.cpp)
  
  add_test(NAME clp_example_testQP
           COMMAND $<TARGET_FILE:testQP> ${Data_DIR}/afiro.mps)
  set_tests_properties(clp_example_testQP PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_testQP PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  endif ()
  
  set_tests_properties(clp_example_testQP PROPERTIES PASS_REGULAR_EXPRESSION "Clp0000I Optimal - objective value -464.75")
  set_tests_properties(clp_example_testQP PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")
  
  
  if (COIN_ENABLE_DOWNLOAD_DATA_TEST)
    add_example(iis ${Clp_DIR}/examples/iis.cpp)
    
    add_test(NAME clp_example_iis
             COMMAND $<TARGET_FILE:iis> ${CMAKE_BINARY_DIR}/Dependencies/DATA_TEST/src/EP_DATA_TEST/Infeas/greenbea.mps)
    set_tests_properties(clp_example_iis PROPERTIES TIMEOUT 30)
    if (WIN32)
      set_tests_properties(clp_example_iis PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
    endif ()

    set(TEST_REGEX )
    add_regex(TEST_REGEX "The following 2 rows cover the IIS")
    add_regex(TEST_REGEX "1491 KTX.CPU.")
    add_regex(TEST_REGEX "53 BLG...AN")
    
    set_tests_properties(clp_example_iis PROPERTIES PASS_REGULAR_EXPRESSION "${TEST_REGEX}")
  endif ()
  
  # Need VOL
  #add_example(useVolume ${Clp_DIR}/examples/useVolume.cpp)
  #
  #add_test(NAME clp_example_useVolume
  #         COMMAND $<TARGET_FILE:useVolume> ${Data_DIR}/afiro.mps)
  #set_tests_properties(clp_example_useVolume PROPERTIES TIMEOUT 30)
  #if (WIN32)
  #  set_tests_properties(clp_example_useVolume PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
  #endif ()
  
  #set(TEST_REGEX )
  #add_regex(TEST_REGEX "")
  #set_tests_properties(clp_example_useVolume PROPERTIES PASS_REGULAR_EXPRESSION "Clp0000I Optimal - objective value -49.857189")
  #set_tests_properties(clp_example_useVolume PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE")

  if (COIN_ENABLE_DOWNLOAD_DATA_TEST)
    # Need OSI to compile
    # This test fails because some Sample tests doesn't pass.
    # On Fedora 26:
    # Severity NOTE      :    0  thereof expected:    0
    # Severity PASSED    : 1100  thereof expected:    0
    # Severity WARNING   :    3  thereof expected:    0
    # Severity ERROR     :  476  thereof expected:    0
    # Tests completed with 476 unexpected errors.
    
    add_example(OsiClpSolverInterfaceTest ${Clp_DIR}/test/OsiClpSolverInterfaceTest.cpp
                                          ${Clp_DIR}/test/osiUnitTest.cpp)
    target_link_libraries(OsiClpSolverInterfaceTest libOsiClp libOsiCommonTests libOsi libCoinUtils)
    
    add_test(NAME clp_example_OsiClpSolverInterfaceTest
             COMMAND $<TARGET_FILE:OsiClpSolverInterfaceTest> -netlibDir=${CMAKE_BINARY_DIR}/Dependencies/DATA_TEST/src/EP_DATA_TEST/Netlib -mpsDir=${Data_DIR} -testOsiSolverInterface -nobuf)
  
    set_tests_properties(clp_example_OsiClpSolverInterfaceTest PROPERTIES TIMEOUT 90)
    if (WIN32)
      set_tests_properties(clp_example_OsiClpSolverInterfaceTest PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_DIR}\\;${TEST_BIN_PATH}")
    endif ()
    set_tests_properties(clp_example_OsiClpSolverInterfaceTest PROPERTIES LABELS "FAIL;DISTRIB;CLP;EXAMPLE")
  endif ()
  
  add_example(osiClpUnitTest ${Clp_DIR}/test/osiUnitTest.cpp ${Clp_DIR}/test/OsiClpSolverInterfaceTest.cpp)
  include_directories(osiClpUnitTest BEFORE PRIVATE ${Osi_DIR}/src/OsiCommonTest ${Osi_DIR}/src/Osi)
  target_link_libraries(osiClpUnitTest libOsiClp libClp libCoinUtils libOsiCommonTests libOsi libCoinUtils)
  if (COINUTILS_HAS_ZLIB OR COIN_USE_ZLIB)
    target_link_libraries(osiClpUnitTest ${ZLIB_NAME})
  endif ()
  if (COINUTILS_HAS_BZLIB OR COIN_USE_BZLIB)
    target_link_libraries(osiClpUnitTest ${BZLIB_NAME})
  endif ()

  add_test(NAME clp_example_osiUnitTest
           COMMAND $<TARGET_FILE:osiClpUnitTest> -mpsDir=${CMAKE_SOURCE_DIR}/Data/Sample)
  set_tests_properties(clp_example_osiUnitTest PROPERTIES TIMEOUT 30)
  if (WIN32)
    set_tests_properties(clp_example_osiUnitTest PROPERTIES ENVIRONMENT "PATH=${TEST_LIB_PATH}\\;${TEST_BIN_PATH}")
  endif ()
  set_tests_properties(clp_example_osiUnitTest PROPERTIES LABELS "DISTRIB;CLP;EXAMPLE;FAIL")
    
  set(TEST_REGEX )
  add_regex(TEST_REGEX "Severity ERROR.*:.*0.*thereof expected:.*0")
  set_tests_properties(clp_example_osiUnitTest PROPERTIES PASS_REGULAR_EXPRESSION "${TEST_REGEX}")
endif ()

add_executable(clp ${Clp_MAIN_SRC_LIST})
target_link_libraries(clp libClpSolver libClp libCoinUtils)
set_include_directories(clp)
if (COIN_COMPILE_LTO)
  set_target_properties(clp PROPERTIES INTERPROCEDURAL_OPTIMIZATION true)
endif ()
if (COIN_HAS_AMD)
  target_link_libraries(clp amd)
endif ()
if (COIN_HAS_CHOLMOD)
  target_link_libraries(clp cholmod suitesparseconfig amd camd ccolamd colamd)
endif ()
if (MKL_FOUND)
  target_link_libraries(clp ${COIN_MKL_LIBS})
else ()
  if (COIN_HAS_LAPACK OR COIN_USE_SYSTEM_LAPACK)
    target_link_libraries(clp lapack)
  endif ()
  if (COIN_HAS_BLAS OR COIN_USE_BLAS)
    target_link_libraries(clp blas)
  endif ()
  if (COIN_ENABLE_DOWNLOAD_CLAPACK)
    target_link_libraries(clp f2c)
  endif ()
  if ((COIN_HAS_BLAS OR COIN_HAS_LAPACK) AND (UNIX OR MINGW) AND NOT COIN_USE_SYSTEM_LAPACK AND NOT (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel"))
    target_link_libraries(clp gfortran)
  endif ()
endif ()
if (COINUTILS_HAS_ZLIB OR COIN_USE_ZLIB)
  target_link_libraries(clp ${ZLIB_NAME})
endif ()
if (COINUTILS_HAS_BZLIB OR COIN_USE_BZLIB)
  target_link_libraries(clp ${BZLIB_NAME})
endif ()
if (COINUTILS_USE_THREADS OR COIN_USE_PTHREAD_WIN32 OR COIN_ENABLE_DOWNLOAD_PTHREAD_WIN32 OR CBC_USE_THREADS)
  if (MINGW)
    target_link_libraries(clp winpthread)
  elseif (NOT WIN32)
    target_link_libraries(clp pthread)
  else ()
    target_link_libraries(clp pthreadVC2)
  endif ()
endif ()
if (COIN_HAS_GLPK OR COIN_USE_GLPK)
  target_link_libraries(clp glpk)
endif ()
if (COIN_HAS_ABC AND (COIN_ABC_LEVEL GREATER 2))
  target_link_libraries(clp cilkrts)
endif ()  
if (COIN_ENABLE_DOWNLOAD_ASL OR COIN_USE_ASL)
  target_link_libraries(clp amplsolver dl)
endif ()  
if (READLINE_FOUND)
  target_link_libraries(clp ${READLINE_LIBRARIES})
endif ()  
if (COIN_HAS_MUMPS)
  if (CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
    target_link_libraries(clp dmumps mumps_common seq blas lapack ifort pthread)
  else ()
    target_link_libraries(clp dmumps mumps_common seq blas lapack gfortran pthread)
  endif ()
endif ()  
if (COIN_ENABLE_DOWNLOAD_METIS OR COIN_USE_METIS)
  target_link_libraries(clp metis m)
endif ()  

install(TARGETS clp
        DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR})

install(TARGETS libClp 
        RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}
        LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}
        ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/static)

install(FILES ${Clp_SRC_LIST_Headers} 
        DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/coin)

install(FILES ${CMAKE_BINARY_DIR}/Clp/include/config_clp.h
        DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/coin
        RENAME ClpConfig.h)

install(FILES ${CMAKE_BINARY_DIR}/Clp/include/config_clp.h
        DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/coin)
